/*
 * @Author: jiegiser changjie@jouav.com
 * @Date: 2023-04-13 10:10:19
 * @LastEditors: WangTao borderpanda@163.com
 * @LastEditTime: 2025-09-04 21:57:08
 * @Description: 请填写简介
 */
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import path, { resolve } from "path";
import cesium from "vite-plugin-cesium";
import fs from "fs";
// import viteCompression from "vite-plugin-compression";
// https://vitejs.dev/config/
/** 获取地图服务的代理 */
export default defineConfig(() => {
  return {
    define: { "process.env": {} },
    plugins: [
      vue(),
      cesium({
        cesiumBaseUrl: "./node_modules/joCesium",
        rebuildCesium: true,
        cesiumBuildRootPath: path.resolve(
          __dirname,
          "./node_modules/joCesium/Build"
        ),
        cesiumBuildPath: path.resolve(
          __dirname,
          "./node_modules/joCesium/Build/Cesium/"
        ),
      }),
    ],
    resolve: {
      extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
      alias: {
        "@": resolve(__dirname, "./src"),
        utils: resolve(__dirname, "./src/utils"),
        // "vue-i18n": "vue-i18n/dist/vue-i18n.cjs.js"
      },
    },
    server: {
      host: "0.0.0.0",
      hmr: true,
    },
    build: {
      outDir: "dist",
      chunkSizeWarningLimit: 1500,
      rollupOptions: {
        output: {
          chunkFileNames: "assets/js/[name]-[hash].js",
          entryFileNames: "assets/js/[name]-[hash].js",
          assetFileNames: "assets/[ext]/[name]-[hash].[ext]",
          manualChunks(id) {
            if (id.includes("node_modules")) {
              return (
                id
                  .toString()
                  .match(/\/node_modules\/(?!.pnpm)(?<moduleName>[^/]*)\//)
                  ?.groups.moduleName ?? "vender"
              );
            }
          },
        },
      },
    },
  };
});
